﻿package app.view.components.video 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import org.casalib.display.CasaSprite;
	/**
	 * ...
	 * @author firsoff maxim, snzflash.com, tel: +79222345364, skype: maxim.firsoff
	 */
	public class ProgressBarBase extends CasaSprite
	{
		public var playLine:Sprite;
		public var sizeLine:Sprite;
		public var loadLine:Sprite;
		
		private var _progressLoading:Number = 0;
		private var _progressPlaying:Number = 0;
		private var _seekValue:Number = 0;
		
		private var _baseWidth:Number = 0;
		
		public function ProgressBarBase() 
		{
			super();
			init();
		}
		
		private function init():void
		{
			sizeLine.visible = false;
			progressLoading = progressLoading;
			progressPlaying = progressPlaying;
			playLine.mouseEnabled = false;
			_baseWidth = sizeLine.width;
			
			loadLine.addEventListener(MouseEvent.CLICK, onLoadLineClick);
		}
		
		
		
		private function onLoadLineClick(event:MouseEvent):void 
		{
			var p:Number = sizeLine.mouseX / _baseWidth * sizeLine.scaleX;
			//trace(sizeLine.mouseX , _baseWidth);
			_seekValue = p;
			progressPlaying = _seekValue;
			dispatchEvent( new Event( Event.CHANGE));
		};
		
		public function reset():void 
		{
			progressLoading = 0;
			progressPlaying = 0;
		};
		
		override public function destroy():void 
		{
			super.destroy();
			loadLine.removeEventListener(MouseEvent.CLICK, onLoadLineClick);
		};
		
		public function get progressLoading():Number { return _progressLoading; };
		
		public function set progressLoading(value:Number):void 
		{
			_progressLoading = value;
			value > 1 ? 1 : value;
			loadLine.width = _baseWidth * value;
		};
		
		public function get progressPlaying():Number { return _progressPlaying; };
		
		public function set progressPlaying(value:Number):void 
		{
			_progressPlaying = value;
			playLine.width = _baseWidth * value;
		};
		
		public function get seekValue():Number { return _seekValue; };
		
	}

}